
$("header").load("header.html");
$("footer").load("footer.html");
let oSmallBox = document.querySelector("#smallbox");
let oBigBox = document.querySelector("#bigbox");
let oMask = document.querySelector("#mask");
let oLis = document.querySelectorAll("li");
let oImg = document.querySelectorAll(".imgLi");
let mf = new Magnifier(oSmallBox, oMask, oBigBox, oLis, oImg);
mf.eventBind();
$(window).scroll(function () {
    if ($(window).scrollTop() > 1500) {
        $("#top_div").show()
    }
    if ($(window).scrollTop() < 1500) {
        $("#top_div").hide()
    }
})
for (let i = 0; i < $(".mian_left_thumb>li").length; i++) {
    $(".mian_left_thumb>li").eq(i).click(function () {
        $(this).attr("class", "selected").siblings().attr("class", " ")
    })
}
let goodsId = location.search.split("=")[1];
console.log(goodsId);
$.get("goodsAndShoppingCart/getGoodsInfo.php?goodsId=" + goodsId,
    function (data) {
        let str = ``;
        console.log(data.goodsName)
        $("#chanpin").html(data.goodsName);
        $("#smallbox").css({ backgroundImage: `url(${data.beiyong2})` })
        $("#bigbox").css({ backgroundImage: `url(${data.beiyong2})` })
        $(".imgLi").eq(0).attr("src", data.beiyong2);
        $(".imgLi").eq(1).attr("src", data.beiyong3);
        $(".imgLi").eq(2).attr("src", data.beiyong4);
        $(".imgLi").eq(3).attr("src", data.beiyong5);
        $(".banner_tu").attr("src", data.beiyong6);
        $(".canshu").attr("src", data.beiyong7);

        str = `
            <div class="main_right right">
                        <p class="main_right_p">
                            <span style="font-size: 24px; color: #000;" id="title">${data.goodsName}</span>
                        </p>
                        <p class="sellPoint">
                        <p class="MsoNormal"></p>
                        <div style="text-align: left;">
                            <p class="MsoNormal">
                                <span style="background-color: #fff;">
                                    <span style="color: rgb(255,77,77); font-size: 14px; font-weight: 700;" class="jieshao">
                                        ${data.goodsDesc}
                                    </span>
                                </span>
                            </p>
                            <p class="MsoNormal">
                                <span style="color: rgb(255,77,77); font-size: 14px; font-weight: 700;" class="jieshao">
                                    ${data.goodsImg}
                                </span>
                            </p>
                        </div>
                        </p>
                        <div class="productActivity">
                            <div class="price">
                                <p class="rightLabel">价 格</p>
                                <div class="PriceContent">
                                    <span class="money">
                                        <i class="priceIcon">¥</i>
                                        ${data.goodsPrice}.00
                                    </span>
                                </div>
                            </div>
                            <div class="promo-sell">
                                <div class="rightLabel">活 动</div>
                                <div class="promo-info">
                                    <p class="spec">
                                        <i class="wrap-txt">分期</i>
                                        <span>享受花呗3期，6期，12期免息分期</span>
                                    </p>
                                    <p>
                                        <i class="wrap-txt">积分</i>
                                        <span>购买即赠积分，积分可抵现</span>
                                    </p>
                                    <p>
                                        <i class="wrap-txt">包邮</i>
                                        <span>青铜及以下满59、白银满39、黄金以及上包邮</span>
                                    </p>
                                </div>
                            </div>
                        </div>
                        <div class="addressMain">
                            <p class="rightLabel">地址</p>
                            <div class="address">
                                <p>
                                    <img src="img/Z30Pro/address.png" alt="">
                                    <span class="address_content">陕西省 西安市 新城区</span>
                                </p>
                                <span class="dh">
                                    <span class="expressprefix">现货</span>
                                    <span class="expresstime">19:00前下单，预计12月12日18:00点前送达</span>
                                </span>
                            </div>
                            <span class="change">修改</span>
                        </div>
                        <div class="productOptions">
                            <div class="phone_net">
                                <p class="rightLabel2">颜色</p>
                                <ul class="clearfix_jj net" id="selectColor">
                                    <li class="" style="border:de634f">${data.beiyong1}</li>
                                    <!-- <li class="">黑金传奇</li>
                                    <li class="cur">星际银</li> -->
                                </ul>
                            </div>
                            <div class="phone_net">
                                <p class="rightLabel2">版本</p>
                                <ul class="clearfix_jj net" id="selectSpec">
                                    <li class=""  style="border:de634f">${data.beiyong9}</li>
                                    <!-- <li class="noShock">16GB+512GB</li>
                                    <li class="cur">8GB+256GB</li> -->
                                </ul>
                            </div>
                            <div class="count" style="overflow: hidden;">
                                <p class="rightLabel">数 量</p>
                                <div class="num">
                                    <div class="minus">
                                        <img src="img/Z30Pro/minus.png" alt="" clas="jian">
                                    </div>
                                    <div class="totle">1</div>
                                    <div class="add">
                                        <img src="img/Z30Pro/add.png" alt="">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="btnGroup">
                            <div class="buy-btn-main">
                                <a class="addShopCar">加入购物车</a>
                                <form action="" id="bottom-buy-btn" method="post" class="buy-now" stock="1">
                                    <input type="hidden" name="buy_from" value="1">
                                    <input type="hidden" id="params" name="item_param">
                                    <a class="button active_button">立即购买</a>
                                </form>
                            </div>
                        </div>
                    </div>
            `
        $(".main_content").prepend(str);
        let num = $(".totle").html()
        $(".minus").click(function () {
            num--;
            if (num <= 0) {
                num = 0
            }
            console.log(num)
            $(".totle").html(num)
        })
        $(".add").click(function () {
            console.log(data.goodsCount)
            if (num > data.goodsCount) {
                num = data.goodsCount
            }
            $(".totle").html(num++);
        })
        let vipName=getCookie("username");
        $(".addShopCar").click(function () {
            if (getCookie("username") != "") {
                location.href="goodscar.html";
                console.log(getCookie("username"))
                $.post(
                    "goodsAndShoppingCart/addShoppingCart.php",
                    {
                        "vipName":vipName,
                        "goodsId": data.goodsId,
                        "goodsCount":num
                    },
                    function (data) {
                        if (data.trim() == 1) {
                            alert("添加成功")
                        }else {
                            alert("添加成失败")
                        }
                    }
                );
            }else{
                location.href="login.html"
            }

        })
    }, "json")
